var isUpdate = false;//是否处于修改的状态
var lastId;//上一个操作的ID
var lastgroup;//开始修改时的权限
var lastactive;//开始修改时的激活状态
//修改
function update(id){
	if(lastId != id){
		if(isUpdate){
			save(lastId);
		}
		isUpdate = true;
		edit(id);
		lastId = id;
	}else{
		if(!isUpdate){
			edit(id);
		}else{
			save(id);
		}
		isUpdate = !isUpdate;
	}
	//isUpdate = !isUpdate;
}
//保存修改
function save(id){
	var sel_group = document.getElementById("sel_group_"+id);
	var sel_active = document.getElementById("sel_active_"+id);
	var group = sel_group.options[sel_group.selectedIndex].text;
	var active = sel_active.options[sel_active.selectedIndex].text;
	
	document.getElementById("txt_group_"+id).value = sel_group.options[sel_group.selectedIndex].value;
	document.getElementById("txt_active_"+id).value = sel_active.options[sel_active.selectedIndex].value;
	
	document.getElementById("update_"+id).src="/thinkphp_cloud/Public/Img/edit.png";
	if(group != lastgroup || active != lastactive){
		if(confirm("您确定要修改该信息？")){
			document.getElementById("group_"+id).innerHTML = group;
			document.getElementById("active_"+id).innerHTML = active;
			document.getElementById("form_"+id).submit();
		}else{
			document.getElementById("group_"+id).innerHTML = lastgroup;
			document.getElementById("active_"+id).innerHTML = lastactive;
		}
	}else{
		document.getElementById("group_"+id).innerHTML = lastgroup;
		document.getElementById("active_"+id).innerHTML = lastactive;
	}
}
//开始修改
function edit(id){
	lastgroup = document.getElementById("group_"+id).innerHTML;
	lastactive = document.getElementById("active_"+id).innerHTML;
	document.getElementById("group_"+id).innerHTML = "<select id='sel_group_"+id+"' name='sel_group' style='font-family:微软雅黑; font-size:14px; background:#f8f8f8; margin-left:10px;'><option value='1'>普通用户</option><option value='3'>VIP用户</option></select>";
	document.getElementById("active_"+id).innerHTML = "<select id='sel_active_"+id+"' name='sel_active' style='font-family:微软雅黑; font-size:14px; background:#f8f8f8; margin-left:20px;'><option value='1'>正常使用</option><option value='0'>黑名单用户</option></select>";

	setSelect("sel_group_"+id,lastgroup);
	setSelect("sel_active_"+id,lastactive);

	document.getElementById("update_"+id).src="/thinkphp_cloud/Public/Img/save.png";
}
//设置下拉框默认项
function setSelect(select_id,text){
	var select = document.getElementById(select_id);
	var ops = select.options;
	for(var i=0;i<ops.length;i++){
		if(ops[i].text == text){
			ops[i].selected = true;
			return;
		}
	}
}
function orderCheck(url,id){
	if(confirm("你确定该订单已消费吗？更改后不可恢复！"))
		  window.location.href = url+'?id='+id;
}
function userDelete(url,id){
	if(confirm("您确定要删除该信息吗？删除后不可恢复！"))
		   window.location.href = url+'?id='+id;
}